package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.framework.widget.uxwidget.hwdotspageindicator.HwTopBannerIndicator;
import com.huawei.appmarket.service.store.awk.bean.BannerV9CardBean;
import com.huawei.appmarket.service.store.awk.bean.BannerV9ListCardBean;
import com.huawei.appmarket.service.store.awk.widget.topbanner.DotsViewPager;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.ArrayList;
import o.azb;
import o.cdn;
import o.cgz;
import o.chy;
import o.dge.d;
import o.dgh;
import o.Logger;
import o.dof;
import o.ContentManager;
import o.eif;
import o.eiz;
import o.ejb;
import o.ejb.a;
import o.epr;
import o.epv;
import o.ewm.j;
import o.ewm.n;

public class BannerV9Card extends BaseDistCard {
    private ejb ʻ = null;
    private eif ʼ;
    private DotsViewPager ʽ = null;
    private HwTopBannerIndicator ˋ = null;
    private chy ͺ;
    private RelativeLayout ॱॱ = null;
    private Context ᐝ;

    public BannerV9Card(Context context) {
        super(context);
        this.ᐝ = context;
    }

    public cgz ˏ(View view) {
        this.ˋ = (HwTopBannerIndicator) view.findViewById(j.ʽᐧ);
        this.ˋ.setIsNeedChangeViewPagerScrollDuration(true);
        this.ˋ.setIsRecycle(true);
        this.ˋ.setScrollDuration(700);
        this.ʽ = (DotsViewPager) view.findViewById(j.ᵎॱ);
        this.ʼ = new eif(this.ᐝ, this.ʽ, this.ˋ, "");
        this.ˋ.setOnPageChangeListener(this.ʼ);
        if (epv.ʼ(this.ᐝ)) {
            LayoutParams layoutParams = (LayoutParams) this.ʽ.getLayoutParams();
            layoutParams.leftMargin = epv.ˋ(this.ᐝ, 8);
            layoutParams.rightMargin = epv.ˋ(this.ᐝ, 8);
        }
        this.ॱॱ = (RelativeLayout) view.findViewById(j.ﹳʼ);
        this.ʻ = new ejb(this.ᐝ, new ArrayList(), new a(this) {
            final /* synthetic */ BannerV9Card ˎ;

            {
                this.ˎ = r1;
            }

            public void ˎ() {
                this.ˎ.ˎ();
            }

            public void ॱ() {
                this.ˎ.ॱॱ();
            }

            public void ˋ() {
                if (this.ˎ.ʽ != null) {
                    int ʼ = this.ˎ.ʽ.ʼ();
                    int childCount = this.ˎ.ʽ.getChildCount();
                    int i = 0;
                    while (i < childCount) {
                        View childAt = this.ˎ.ʽ.getChildAt(i);
                        int[] iArr = new int[2];
                        childAt.getLocationOnScreen(iArr);
                        if (ʼ < iArr[0] || ʼ > iArr[0] + childAt.getWidth()) {
                            i++;
                        } else {
                            Object tag = childAt.getTag(j.ٴ);
                            if (tag instanceof BannerV9CardBean) {
                                BaseCardBean baseCardBean = (BannerV9CardBean) tag;
                                this.ˎ.ˊᐝ = baseCardBean;
                                if (this.ˎ.ͺ != null) {
                                    this.ˎ.ͺ.ˏ(0, this.ˎ);
                                }
                                this.ˎ.ˋ(baseCardBean);
                                return;
                            }
                            return;
                        }
                    }
                }
            }
        });
        this.ʽ.setAdapter(this.ʻ);
        this.ˋ.setViewPager(this.ʽ, 0);
        ʽ(view);
        return this;
    }

    private void ˋ() {
        if (epr.ˎ().ॱॱ() || cdn.ॱॱ()) {
            this.ॱॱ.setOnTouchListener(new OnTouchListener(this) {
                final /* synthetic */ BannerV9Card ˊ;

                {
                    this.ˊ = r1;
                }

                public boolean onTouch(View view, MotionEvent motionEvent) {
                    return this.ˊ.ʽ.dispatchTouchEvent(motionEvent);
                }
            });
            Logger.ˎ("BannerV9Card", "Pad mode");
            ॱ(0.7d, 0.636d);
        } else if (azb.ˎ(this.ᐝ)) {
            this.ॱॱ.setOnTouchListener(new OnTouchListener(this) {
                final /* synthetic */ BannerV9Card ˊ;

                {
                    this.ˊ = r1;
                }

                public boolean onTouch(View view, MotionEvent motionEvent) {
                    return this.ˊ.ʽ.dispatchTouchEvent(motionEvent);
                }
            });
            Logger.ˎ("BannerV9Card", "Landscape mode");
            ॱ(0.7d, 0.636d);
        } else if (this.ॱॱ != null) {
            ViewGroup.LayoutParams layoutParams = this.ॱॱ.getLayoutParams();
            int ॱ = azb.ॱ(this.ᐝ);
            LayoutParams layoutParams2 = (LayoutParams) this.ʽ.getLayoutParams();
            int ˊ = azb.ˊ(this.ᐝ);
            int ˏ = azb.ˏ(this.ᐝ);
            int i = (((int) (((float) ॱ) + 0.5f)) - ˊ) - ˏ;
            Logger.ˎ("BannerV9Card", "realWidth = " + ॱ + " , layoutWidth = " + layoutParams.width);
            layoutParams.height = (int) ((((double) i) * 0.636d) + 0.5d);
            layoutParams2.leftMargin = ˊ / 2;
            layoutParams2.rightMargin = ˏ / 2;
            this.ॱॱ.setLayoutParams(layoutParams);
            this.ʽ.setLayoutParams(layoutParams2);
        }
    }

    private void ॱ(double d, double d2) {
        if (this.ʽ != null) {
            this.ʽ.setFactor((float) d2);
        }
        if (this.ʽ != null && (this.ʽ.getLayoutParams() instanceof LayoutParams)) {
            LayoutParams layoutParams = (LayoutParams) this.ʽ.getLayoutParams();
            int ॱ = epv.ॱ(this.ᐝ);
            int ॱ2 = azb.ॱ(this.ᐝ);
            ॱ = ˊ(d, ॱ2, ॱ);
            Logger.ˎ("BannerV9Card", "bannerWidth = " + ॱ);
            ॱ2 -= ॱ;
            layoutParams.leftMargin = (int) ((((float) ॱ2) * 0.5f) + 0.5f);
            layoutParams.rightMargin = (int) ((((float) ॱ2) * 0.5f) + 0.5f);
            if (this.ॱॱ != null) {
                ViewGroup.LayoutParams layoutParams2 = this.ॱॱ.getLayoutParams();
                layoutParams2.height = (int) ((((double) ॱ) * d2) + 0.5d);
                this.ॱॱ.setLayoutParams(layoutParams2);
            }
            this.ʽ.setLayoutParams(layoutParams);
        }
    }

    private int ˊ(double d, int i, int i2) {
        if (epr.ˎ().ॱॱ()) {
            if (azb.ˎ(this.ᐝ)) {
                return (int) ((((double) i2) * d) + 0.5d);
            }
            return (int) ((((double) i) * d) + 0.5d);
        } else if (!cdn.ॱॱ()) {
            return (((int) (((float) i2) + 0.5f)) - azb.ˊ(this.ᐝ)) - azb.ˏ(this.ᐝ);
        } else {
            if (azb.ˎ(this.ᐝ)) {
                return (((int) ((((float) i2) * 0.52f) + 0.5f)) - azb.ˊ(this.ᐝ)) - azb.ˏ(this.ᐝ);
            }
            return (((int) ((((float) i) * 0.52f) + 0.5f)) - azb.ˊ(this.ᐝ)) - azb.ˏ(this.ᐝ);
        }
    }

    public void ˎ(ImageView imageView, String str, String str2) {
    }

    public void ˏ(CardBean cardBean) {
        this.ˊᐝ = cardBean;
        this.ʼ.ˏ(cardBean.ॱˉ());
        boolean ॱᐧ = cardBean.ॱᐧ();
        ˋ();
        if (epv.ʼ(this.ᐝ)) {
            this.ʽ.setOffscreenPageLimit(1);
        } else {
            this.ʽ.setOffscreenPageLimit(2);
        }
        if (this.ˋ != null) {
            this.ˋ.setmFragmentSelected(ॱᐧ);
            this.ˋ.setTag(cardBean);
        }
        if (cardBean instanceof BannerV9ListCardBean) {
            if ((this.ʻ.getCount() > 0 || ॱᐧ) && this.ʻ.ˋ(((BannerV9ListCardBean) cardBean).ˊ())) {
                this.ˋ.setViewPager(this.ʽ, ((BannerV9ListCardBean) cardBean).ˊ().size());
                this.ʽ.setCurrentItem(this.ˋ.ˏ(), false);
            }
            if (ॱᐧ && this.ˋ != null) {
                this.ˋ.ˋ();
            }
        }
    }

    private void ˎ() {
        if (this.ˋ != null) {
            this.ˋ.ˋ();
        }
    }

    private void ॱॱ() {
        if (this.ˋ != null) {
            this.ˋ.ॱ();
        }
    }

    public ArrayList<String> ˊ() {
        if (this.ʽ == null) {
            return null;
        }
        int ˋ = this.ʽ.getCurrentItem();
        int childCount = this.ʽ.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = this.ʽ.getChildAt(i);
            if (childAt != null) {
                Object tag = childAt.getTag(j.ߺ);
                if ((tag instanceof Integer) && ˋ == ((Integer) tag).intValue()) {
                    tag = childAt.getTag(j.ٴ);
                    if (tag instanceof BannerV9CardBean) {
                        ArrayList<String> arrayList = new ArrayList();
                        BannerV9CardBean bannerV9CardBean = (BannerV9CardBean) tag;
                        arrayList.add(bannerV9CardBean.ॱॱ() + "#$#" + bannerV9CardBean.u_());
                        return arrayList;
                    }
                    return null;
                }
            }
        }
        return null;
    }

    private void ˋ(BaseCardBean baseCardBean) {
        String ॱˉ = baseCardBean.ॱˉ();
        dgh.onEvent(new d(ContentManager.getInstant().getContext(), n.ᐝˋ).ˏ(eiz.ˊ(ॱˉ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + dof.ʼ(baseCardBean.ॱॱ()).replaceAll("\\|", "#$#") + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + baseCardBean.u_())).ˋ());
    }

    public void ˎ(chy o_chy) {
        this.ͺ = o_chy;
    }
}
